<!DOCTYPE html>
<html>
<head>
	<title></title>
	<link rel="stylesheet" type="text/css" href="admin.css">
</head>
<script type="text/javascript">

	var nowIndex = 1
	function checkMenu(i) {

		for (var index = 1; index < 5; index++) {
			document.getElementById("mm" + index.toString()).style.background="#ABABAB";
			document.getElementById("content" + index.toString()).style.display="none";
		}

		document.getElementById("mm" + i.toString()).style.background="#DCDCDC";
		document.getElementById("content" + i.toString()).style.display="";


		// alert(str);
	}
</script>
<body>
<div id="menu">
	<ul>
		<li><a href="#" id = "mm1" onclick="checkMenu(1)" style="background-color: #DCDCDC">内容管理</a></li>
		<li><a href="#" id = "mm2" onclick="checkMenu(2)">用户管理</a></li>
		<li><a href="#" id = "mm3" onclick="checkMenu(3)">后台管理</a></li>
		<li><a href="#" id = "mm4" onclick="checkMenu(4)">控制面板</a></li>
	</ul>
</div>

<!-- 内容 -->
<?php 
	$host = 'localhost';
	$root = 'root';
	$pwd = 'root';
	$db = 'mymessageboard';
	$table = 'Messages';
	// 数据库连接
	$con = mysqli_connect($host, $root, $pwd);
	if (!$con) {
		echo "数据库连接失败<br>";
	}

	if (!mysqli_select_db($con, $db)) {
		echo "连接该数据库失败: $db <br>";
	}

	function getSome() {

		
	}
	// 取值(内容)
	$sql = "Select m.*,p.name, p.id as userid from Messages m INNER join Persons p on m.personid = p.id order by p.id";
	$ret = mysqli_query($con, $sql);
	if (!$ret) {
		echo "该表为空<br>";
	} else {
		$messageContent = $ret;
	}

	// 用户
	$sql = "select * from Persons order by id";
	$ret = mysqli_query($con, $sql);
	if (!$ret) {
		echo "表是空的";
	} else {
		$persons = $ret;
	}

?>

<div id="content">
	<div id="content1">
	<?php 
		while($row = mysqli_fetch_array($messageContent)) {
			$personid = $row["userid"];
			$title = $row["title"];
			$msgid = $row["id"];
			$content = $row["content"];
			$createtime = $row["createtime"];
			$personname = $row["name"];

			// $str = "<td>";
			$str = "<li><a href='messagedetail.php?id=". $msgid ."'>" . "文章id = " . $msgid . ", 输出标题 = " . $row["title"] . ", 内容 = " . $content .", 名字 = " . $personname . ", 用户id = " . $personid . "<br>" .  "</li></a>";
			echo $str;
		}
	?>
	</div>

	<!-- 用户管理 -->
	<div id="content2" style="display: none;">
	<?php
		$index = 0;
		$h = "";
		while ($row = mysqli_fetch_array($ret)) {
			$ss =  "id = " . $row["id"] . ", name = " . $row["name"] . ",age = " . $row["age"] . ",email = " . $row["email"] . ",createtime = " . $row["createtime"] . "<br>"; 

			// 拼接参数
			$par =  "id=" . $row["id"] . "&name=" . $row["name"] . "&age=" . $row["age"] . "&email=" . $row["email"] . "&createtime=" . $row["createtime"]; 

			$h .= "<a href='writesomething.php?" . $par . "'>" . $ss . "</a>";

			$arr[$index] = array("id"=>$row["id"], 
								 "name"=>$row["name"],
								 "age"=>$row["age"],
								 "email"=>$row["email"],
								 "createtime"=>$row["createtime"]);
			$index++;
		}
		echo $h;

	?>
	</div>

	<div id="content3" style="display: none;"></div>

	<div id="content4" style="display: none;"></div>
	

</div>
</body>
</html>